﻿Public Class frmDates
    Public pSelection As String

    Private Sub frmDates_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If IsDate(gDate_debut) Then
            TE_DATE_DEBUT.Value = gDate_debut
            If IsDate(gDate_fin) Then
                TE_DATE_FIN.Value = gDate_fin
            Else
                ' date de fin = date de début fin de mois
                TE_DATE_FIN.Value = TE_DATE_DEBUT.Value.AddMonths(1)
                TE_DATE_FIN.Value = TE_DATE_FIN.Value.AddDays(-1)
            End If
        Else
            ' période = mois en cours
            TE_DATE_DEBUT.Value = CDate(Now.Year.ToString & "/" & Now.Month.ToString & "/01")
            TE_DATE_FIN.Value = TE_DATE_DEBUT.Value.AddMonths(1)
            TE_DATE_FIN.Value = TE_DATE_FIN.Value.AddDays(-1)
        End If
        pSelection = ""

    End Sub

    Private Sub BO_IMPRIMER_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BO_IMPRIMER.Click

        If DateDiff("d", TE_DATE_DEBUT.Value, TE_DATE_FIN.Value) < 0 Then
            MsgBox("Date début et la Date fin incompatible ...")
            TE_DATE_DEBUT.Focus()
        Else
            ' mémoriser les dates saisies
            gDate_debut = TE_DATE_DEBUT.Value
            gDate_fin = TE_DATE_FIN.Value
            pSelection = "du " & Format(TE_DATE_DEBUT.Value, "dd/MM/yyyy") & " au " & Format(TE_DATE_FIN.Value, "dd/MM/yyyy")
            Me.Close()
        End If

    End Sub
End Class